package com.huike.web.controller.report;


import com.huike.clues.domain.vo.IndexStatisticsVo;
import com.huike.common.utils.SecurityUtils;
import com.huike.report.domain.vo.IndexTodayInfoVO;
import com.huike.report.domain.vo.IndexTodoInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;

    /**
     * 首页--基础数据统计
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime,endCreateTime));
    }

    /**
     * 今日简报
     * @return
     */
    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo(){

//        List<Map<String, Object>> mapList = new ArrayList<>();
        String username = SecurityUtils.getUsername();
        Integer todayCluesNum =  reportService.getTodayCluesNum(username);
        Integer todayBusinessNum = reportService.getTodayBusinessNum(username);
        Integer todayContractNum = reportService.getTodayContractNum(username);
        Integer todaySalesAmount = reportService.getTodaySalesAmount(username);
        Map map = new HashMap<String,Object>();
        map.put("todayCluesNum",todayCluesNum);
        map.put("todayBusinessNum",todayBusinessNum);
        map.put("todayContractNum",todayContractNum);
        map.put("todaySalesAmount",todaySalesAmount);
        return AjaxResult.success(map);
    }

    @GetMapping("/getTodoInfo")
    public AjaxResult getTodoInfo(@RequestParam("beginCreateTime") String beginCreateTime,@RequestParam("endCreateTime") String endCreateTime){
        IndexTodoInfoVO indexTodoInfoVO = reportService.getTodoInfo(beginCreateTime,endCreateTime);
        return AjaxResult.success(indexTodoInfoVO);
    }

    /**
     * 商机龙虎榜
     * @param request
     * @return
     */
    @GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(IndexStatisticsVo request){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        request.setBeginCreateTime(request.getBeginCreateTime()+" 00:00:00");
        request.setEndCreateTime(request.getEndCreateTime()+" 23:59:59");
        List<Map<String,Object>> list= reportService.businessChangeStatisticsForIndex(request);
        return AjaxResult.success(list);
    }

    /**
     * 线索龙虎榜
     * @param request
     * @return
     */
    @GetMapping("/salesStatistic")
    public AjaxResult salesStatistics(IndexStatisticsVo request){
        request.setBeginCreateTime(request.getBeginCreateTime()+" 00:00:00");
        request.setEndCreateTime(request.getEndCreateTime()+" 23:59:59");
        List<Map<String,Object>> list= reportService.clueChangeStatisticsForIndex(request);
        return AjaxResult.success(list);
    }
}